//  Life Cycle of an Applet 
package Applets;
import java.applet.Applet;
import java.awt.*;

public class LifeCycle extends Applet
{ 
    int initCount=0;
    int startCount=0;
    int stopCount=0;
    int destroyCount=0;
    int startPaint=0;
  
    @Override
    public void init()
    { 
        ++initCount;
        setBackground(Color.lightGray);  
        System.out.println("init(): " + initCount);
    }
    @Override
    public void start()
    { 
        ++startCount;
        System.out.println("start() " + startCount);
    }
    @Override
    public void paint(Graphics g)
    { 
        Color c1 = new Color(255,100,100);
	int a=10, b=7;  
	Dimension d = this.getSize();  //get the size of applet window
  	++startPaint;
        System.out.println("paint() " + startPaint);
	for (int i = 0; i < 4 ; i++)
		g.drawString( "Welcome to Java Programming!", 25 + 3*i, 
                        25 + 12*i );
	g.drawRect(100,130,60,50);
	g.setColor(c1);	
	g.drawOval(10,400,30,30);	
	g.fillOval(220,10,90,30);
	g.setColor(Color.green);
	g.drawArc(10,100,70,80,0,175);
	d = getSize();		
	g.drawLine(0,d.height-1, d.width-1,0);
	a = difference(a,b);
	g.drawString("The differrence between "+a+" and "+b+ " = "+
                difference(a,b),100,100);
    }
    @Override
    public void stop()
    {
        ++stopCount;
        System.out.println("stop() " + stopCount);
    }
  
    public int difference(int x, int y)
    {
  	return x - y;
    }
    @Override
    public void destroy()
    { 
        ++destroyCount;
        System.out.println("destroy() " + destroyCount);
    }
}
